package com.song.BeanFactoryTest;


import com.sun.xml.internal.ws.addressing.v200408.MemberSubmissionWsaClientTube;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * @Description: SpringTest：类描述
 * @author: songzhangyong
 * @Date: 2019/10/27 10:52
 */
public class FactoryBeanTest {

	static ReadWriteLock readWriteLock = new ReentrantReadWriteLock();



	public static void main(String[] args) {
		readWriteLock.readLock().unlock();

		List<String> ss = new ArrayList<>();



		BeanFactory baen =  new AnnotationConfigApplicationContext(SpringSong.class);
		baen.getBean("&userServiceImplBean");

		AnnotationConfigApplicationContext acont = new AnnotationConfigApplicationContext(SpringSong.class);


		/**
		 如果实现了FactoryBean接口，则当前的对象在sprng中会有两个对象
		 1、getObject 返回的对象
		 2、当前类的对象
		 (UserServiceImplBean) acont.getBean("&userServiceImplBean") 获取的是当前的对象，也就是beanname前面需要加上一个 “&”
		 (UserServiceImplBean2) acont.getBean("userServiceImplBean") 获取的是getObject返回的对象。这里没有 “&”
		 */

		UserServiceImplBean userServiceImplBean = (UserServiceImplBean) acont.getBean("&userServiceImplBean");
		userServiceImplBean.factoryBeanTest();

		UserServiceImplBean2 userServiceImplBean2 = (UserServiceImplBean2) acont.getBean("userServiceImplBean");
		userServiceImplBean2.factoryBeanTest();


	}
}

